package org.john.common.util;

import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.john.common.exception.AssertionException;

public class Assertion {

	private Assertion() {
		throw new IllegalStateException("Constant class");
	}

	public static void isNegative(short value, String message) {
		validate(!Detect.isNegative(value), message);
	}

	public static void isPositive(short value, String message) {
		validate(!Detect.isPositive(value), message);
	}

	public static void isNegative(int value, String message) {
		validate(!Detect.isNegative(value), message);
	}

	public static void isPositive(int value, String message) {
		validate(!Detect.isPositive(value), message);
	}

	public static void isNegative(long value, String message) {
		validate(!Detect.isNegative(value), message);
	}

	public static void isPositive(long value, String message) {
		validate(!Detect.isPositive(value), message);
	}

	public static void isNegative(float value, String message) {
		validate(!Detect.isNegative(value), message);
	}

	public static void isPositive(float value, String message) {
		validate(!Detect.isPositive(value), message);
	}

	public static void isNegative(double value, String message) {
		validate(!Detect.isNegative(value), message);
	}

	public static void isPositive(double value, String message) {
		validate(!Detect.isPositive(value), message);
	}

	public static void notEmpty(String[] string, String message) {
		validate(ArrayUtils.isEmpty(string), message);
	}

	public static void notEmpty(long[] values, String message) {
		validate(ArrayUtils.isEmpty(values), message);
	}

	public static void notEmpty(byte[] values, String message) {
		validate(ArrayUtils.isEmpty(values), message);
	}

	public static void notEmpty(short[] values, String message) {
		validate(ArrayUtils.isEmpty(values), message);
	}

	public static void notEmpty(int[] values, String message) {
		validate(ArrayUtils.isEmpty(values), message);
	}

	public static void notEmpty(List<?> list, String message) {
		validate(list.isEmpty(), message);
	}

	public static void notEmpty(String string, String message) {
		validate(StringUtils.isEmpty(string), message);
	}

	public static void isEmpty(String[] string, String message) {
		validate(ArrayUtils.isNotEmpty(string), message);
	}

	public static void isEmpty(long[] values, String message) {
		validate(ArrayUtils.isNotEmpty(values), message);
	}

	public static void isEmpty(List<?> list, String message) {
		validate(!list.isEmpty(), message);

	}

	public static void isEmpty(String string, String message) {
		validate(StringUtils.isNotEmpty(string), message);
	}

	public static void isTrue(boolean expression, String message) {
		validate(!expression, message);
	}

	public static void isFalse(boolean expression, String message) {
		validate(expression, message);
	}

	public static void isNull(Object object, String message) {
		validate(object != null, message);
	}

	public static void notNull(Object object, String message) {
		validate(object == null, message);
	}

	public static void isNegative(short value, String message, int httpStatusCode) {
		validate(!Detect.isNegative(value), message, httpStatusCode);
	}

	public static void isPositive(short value, String message, int httpStatusCode) {
		validate(!Detect.isPositive(value), message, httpStatusCode);
	}

	public static void isNegative(int value, String message, int httpStatusCode) {
		validate(!Detect.isNegative(value), message, httpStatusCode);
	}

	public static void isPositive(int value, String message, int httpStatusCode) {
		validate(!Detect.isPositive(value), message, httpStatusCode);
	}

	public static void isNegative(long value, String message, int httpStatusCode) {
		validate(!Detect.isNegative(value), message, httpStatusCode);
	}

	public static void isPositive(long value, String message, int httpStatusCode) {
		validate(!Detect.isPositive(value), message, httpStatusCode);
	}

	public static void isNegative(float value, String message, int httpStatusCode) {
		validate(!Detect.isNegative(value), message, httpStatusCode);
	}

	public static void isPositive(float value, String message, int httpStatusCode) {
		validate(!Detect.isPositive(value), message, httpStatusCode);
	}

	public static void isNegative(double value, String message, int httpStatusCode) {
		validate(!Detect.isNegative(value), message, httpStatusCode);
	}

	public static void isPositive(double value, String message, int httpStatusCode) {
		validate(!Detect.isPositive(value), message, httpStatusCode);
	}

	public static void notEmpty(String[] string, String message, int httpStatusCode) {
		validate(ArrayUtils.isEmpty(string), message, httpStatusCode);
	}

	public static void notEmpty(long[] values, String message, int httpStatusCode) {
		validate(ArrayUtils.isEmpty(values), message, httpStatusCode);
	}

	public static void notEmpty(byte[] values, String message, int httpStatusCode) {
		validate(ArrayUtils.isEmpty(values), message, httpStatusCode);
	}

	public static void notEmpty(short[] values, String message, int httpStatusCode) {
		validate(ArrayUtils.isEmpty(values), message, httpStatusCode);
	}

	public static void notEmpty(int[] values, String message, int httpStatusCode) {
		validate(ArrayUtils.isEmpty(values), message, httpStatusCode);
	}

	public static void notEmpty(List<?> list, String message, int httpStatusCode) {
		validate(list.isEmpty(), message, httpStatusCode);
	}

	public static void notEmpty(String string, String message, int httpStatusCode) {
		validate(StringUtils.isEmpty(string), message, httpStatusCode);
	}

	public static void isEmpty(String[] string, String message, int httpStatusCode) {
		validate(ArrayUtils.isNotEmpty(string), message, httpStatusCode);
	}

	public static void isEmpty(long[] values, String message, int httpStatusCode) {
		validate(ArrayUtils.isNotEmpty(values), message, httpStatusCode);
	}

	public static void isEmpty(List<?> list, String message, int httpStatusCode) {
		validate(!list.isEmpty(), message, httpStatusCode);

	}

	public static void isEmpty(String string, String message, int httpStatusCode) {
		validate(StringUtils.isNotEmpty(string), message, httpStatusCode);
	}

	public static void isTrue(boolean expression, String message, int httpStatusCode) {
		validate(!expression, message, httpStatusCode);
	}

	public static void isFalse(boolean expression, String message, int httpStatusCode) {
		validate(expression, message, httpStatusCode);
	}

	public static void isNull(Object object, String message, int httpStatusCode) {
		validate(object != null, message, httpStatusCode);
	}

	public static void notNull(Object object, String message, int httpStatusCode) {
		validate(object == null, message, httpStatusCode);
	}

	private static void validate(boolean expression, String message) {
		validate(expression, message, AssertionException.DEFAULT_HTTP_STATUS_CODE);
	}

	private static void validate(boolean expression, String message, Integer defaultHttpStatusCode) {
		if (expression) {
			throw new AssertionException(message, defaultHttpStatusCode);
		}
	}

}
